#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-06-17 23:04:35
# @Author  : shitao.tommy (hero007asd@gmail.com)
# @Link    : http://example.org
# @Version : $Id$

import os
import time
from datetime import datetime

from celery import Celery


app = Celery("tasks", broker="amqp://guest@localhost:5672//")
app.conf.CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'amqp')


@app.task
def add(x, y):
    return int(x) + int(y)


@app.task
def sleep(seconds):
    time.sleep(float(seconds))
    return seconds


@app.task
def echo(msg, timestamp=False):
    return "%s: %s" % (datetime.now(), msg) if timestamp else msg


@app.task
def error(msg):
    raise Exception(msg)


# if __name__ == "__main__":
#     app.start()